package formal.queueStack;

import java.util.Stack;

/**
 * @author DengYuan2
 * @create 2021-01-27 22:03
 */
public class E_232 {

    class MyQueue {
        private Stack<Integer> in = new Stack<>();
        private Stack<Integer> out = new Stack<>();

        public void push(int x) {
            in.push(x);
        }

        public int pop() {
            in2Out();
            return out.pop();
        }

        public int peek() {
            in2Out();
            return out.peek();
        }

        public void in2Out() {
            if (out.isEmpty()) {
                while (!in.isEmpty()) {
                    out.push(in.pop());
                }
            }
        }


        public boolean empty() {
            return in.isEmpty() && out.isEmpty();
        }
    }
}
